$(document).ready(function(){					
	var canvas = document.getElementById('canvas');//画布
	var stage = new JTopo.Stage(canvas);//舞台
	stage.frames = -24; //舞台帧数
	var scene = new JTopo.Scene(stage);//场景
	//显示工具栏 showJTopoToobar(stage);
	scene.background = './img/bg.jpg';//场景背景图片
	
	//新建节点
	function newNode(x,y,w,h,text){ //新建节点函数
		var node = new JTopo.Node(text);
		node.setBound(x,y,w,h);
		scene.add(node);
		return node;
	}
	
	//简单连线
	function newLink(nodeA, nodeZ, text, dashedPattern){
		var link = new JTopo.Link(nodeA, nodeZ, text);
		link.lineWidth = 3;//线宽
		link.bundleOffset = 60; // 折线拐角处的长度
		link.bundleGap = 20; // 线条之间的间隔
		link.textOffsetY = 3; // 文本偏移量（向下3个像素）
		link.strokeColor = JTopo.util.randomColor();//随机色
		link.dashedPattern = dashedPattern;// 虚线, 虚段长度
		scene.add(link);
		return link;
	}
	
	var fromNode = newNode(100, 80, 60, 60, 'from');
	var node = newNode(360, 250, 60, 60, 'to');
	
	for(var i = 0; i< 5 ; i++){
		newLink(fromNode, node, 'Link' + i);
	}
	newLink(fromNode, node, 'last', 5);
	
	// 折线
	function newFoldLink(nodeA, nodeZ, text, direction, dashedPattern){
		var link = new JTopo.FoldLink(nodeA, nodeZ, text);
		link.direction = direction || 'horizontal'; //连线方向 //horizontal:水平的, vertical:垂直的
		link.arrowsRadius = 15; //箭头大小
		link.lineWidth = 3; // 线宽
		link.bundleOffset = 60; // 折线拐角处的长度
		link.bundleGap = 20; // 线条之间的间隔
		link.textOffsetY = 3; // 文本偏移量（向下3个像素）
		link.strokeColor = JTopo.util.randomColor(); // 线条颜色随机
		link.dashedPattern = dashedPattern;
		scene.add(link);
		return link;
	}
	
	var fromNode = newNode(100, 320, 60, 60, 'from');	
	var node = newNode(300, 470, 60, 60, 'to');
	
	newFoldLink(fromNode, node, 'up');
	newFoldLink(fromNode, node, 'down', 'vertical');
	
	// 二次折线
	function newFlexionalLink(nodeA, nodeZ, text, dashedPattern){
		var link = new JTopo.FlexionalLink(nodeA, nodeZ, text);
		link.arrowsRadius = 10; //箭头大小
		link.lineWidth = 3; // 线宽
		link.offsetGap = 35;//折点距离node 距离
		link.bundleGap = 15; // 线条之间的间隔
		link.textOffsetY = 10; // 文本偏移量
		link.strokeColor = JTopo.util.randomColor();
		link.dashedPattern = dashedPattern;
		scene.add(link);
		return link;
	}
	
	var fromNode = newNode(500, 60, 60, 60, 'from');
	var node = newNode(545, 220, 60, 60, 'to');
	
	for(var i=0; i<2; i++){
		newFlexionalLink(fromNode, node, 'u' + i, 3);
		newFlexionalLink(node, fromNode);
	}
	
	// 曲线
    function newCurveLink(nodeA, nodeZ, text){
        var link = new JTopo.CurveLink(nodeA, nodeZ, text);
        link.lineWidth = 3; // 线宽
        scene.add(link);
        return link;
    }
    
    var loopNode = newNode(600, 400, 60, 60, 'loop');
    for(var i=0; i<3; i++){
		var link = new JTopo.Link(loopNode, loopNode);
		link.text = 'L'+i;
		link.lineWidth = 3; // 线宽
		link.bundleGap = 20; // 线条之间的间隔
		link.textOffsetY = 3; // 文本偏移量（向下3个像素）
		link.strokeColor = JTopo.util.randomColor(); // 线条颜色随机
		link.type = 'loop'; // 自定义属性
		scene.add(link);
	}
	
	
	
});
	